package cn.tedu.adminsystem.webapi.controller;


import cn.tedu.adminsystem.service.SlideshowService;
import cn.tedu.community.commons.pojo.slideshow.vo.SlideshowList;
import cn.tedu.community.commons.restful.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/slideshow")
@Validated
public class SlideshowController {
    @Autowired
    private SlideshowService service;

    @PostMapping("/photo={photo}/addNew")
    public JsonResult<Void> addNew(@NotBlank(message = "请选择照片！") @PathVariable String photo){
        log.debug("控制层开始处理添加轮播图，图片url是：{}",photo);
        service.addNew(photo);
        return JsonResult.ok();
    }

    @GetMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> deleteById(@PathVariable Long id) {
        log.debug("需要删除的轮播图id是：{}", id);
        service.deleteById(id);
        return JsonResult.ok();
    }

    @GetMapping("/list")
    public JsonResult<List<SlideshowList>> list() {
        log.debug("控制层开始处理展示轮播图列表");
        List<SlideshowList> slideshowList = service.getSlideshowList();
        log.debug("查询完成，展示轮播图列表：{}",slideshowList);
        return JsonResult.ok(slideshowList);
    }
}
